//
//  SuperWebViewViewController.m
//  WhereToTravel
//
//  Created by dlios on 15/10/17.
//  Copyright © 2015年 zhoushengmin. All rights reserved.
//

#import "SuperWebViewViewController.h"
#import "CountryModel.h"

@interface SuperWebViewViewController ()<UIScrollViewDelegate,UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *destinationWebView;
@property (nonatomic, strong) UIWebView *trafficWebView;
@property (nonatomic, strong) UIWebView *costWebView;
@property (nonatomic, strong) UIWebView *PracticalWebView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *countryArr;
@property (nonatomic, strong) NSMutableArray *cityArr;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, copy) NSString *desStr;
@property (nonatomic, copy) NSString *traStr;
@property (nonatomic, copy) NSString *praStr;
@property (nonatomic, copy) NSString *costStr;

@end

@implementation SuperWebViewViewController

// 视图的出现将tabbar隐藏
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)creatData {
    NSLog(@"-----------------------%@",self.countryId);
    NSString *str = [NSString stringWithFormat:@"http://open.qyer.com/qyer/place/country_useful_info?client_id=qyer_android&client_secret=9fcaae8aefc4f9ac4915&v=1&track_deviceid=863151025525517&track_app_version=6.7.1&track_app_channel=baidu&track_device_info=mx3&track_os=Android4.4.4&app_installtime=1444613810999&country_id=%@",self.countryId];
    [ZSMAFNetWork geturl:str body:nil result:ZSMJSON headerFile:nil success:^(id result) {
        NSLog(@"%@火火火火火",result);
      NSArray *arr = result[@"data"];
        self.countryArr = [NSMutableArray array];
        for (NSDictionary *dic in arr) {
            CountryModel *modelCoun = [[CountryModel alloc]initWithDic:dic];
            [self.countryArr addObject:modelCoun];
        }
        if (self.countryArr.count >= 4) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];
            NSURL *trafficUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[1]).appview_url];
            NSURLRequest *trafficRequest = [NSURLRequest requestWithURL:trafficUrl];
            [self.trafficWebView loadRequest:trafficRequest];
            NSURL *costUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[2]).appview_url];
            NSURLRequest *costRequest = [NSURLRequest requestWithURL:costUrl];
            [self.costWebView loadRequest:costRequest];
            NSLog(@"%@",costRequest);
            NSURL *PracticalUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[3]).appview_url];
            NSURLRequest *PracticalRequest = [NSURLRequest requestWithURL:PracticalUrl];
            [self.PracticalWebView loadRequest:PracticalRequest];
            self.scrollView.contentSize = CGSizeMake(WIDTH * 1500, 0);
        }else if (self.countryArr.count == 3) {
            
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];
            NSURL *trafficUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[1]).appview_url];
            NSURLRequest *trafficRequest = [NSURLRequest requestWithURL:trafficUrl];
            [self.trafficWebView loadRequest:trafficRequest];
            self.scrollView.contentSize = CGSizeMake(WIDTH * 1125, 0);
        }else if (self.countryArr.count == 2) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            NSURL *trafficUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[1]).appview_url];
            NSURLRequest *trafficRequest = [NSURLRequest requestWithURL:trafficUrl];
            [self.trafficWebView loadRequest:trafficRequest];
            [self.destinationWebView loadRequest:destinationRequest];
            self.scrollView.contentSize = CGSizeMake(WIDTH * 750, 0);
        }else if (self.countryArr.count == 1) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.countryArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];

        }
        
        
    } failure:^(NSError *error) {
        
    }];
    NSString *utr = [NSString stringWithFormat:@"http://open.qyer.com/qyer/place/city_useful_info?client_id=qyer_android&client_secret=9fcaae8aefc4f9ac4915&v=1&track_deviceid=863151025525517&track_app_version=6.7.1&track_app_channel=baidu&track_device_info=mx3&track_os=Android4.4.4&app_installtime=1444613810999&city_id=%@",self.cityId];
    [ZSMAFNetWork geturl:utr body:nil result:ZSMJSON headerFile:nil success:^(id result) {
        NSArray *arr = result[@"data"];
        self.cityArr = [NSMutableArray array];
        for (NSDictionary *dic in arr) {
            CountryModel *modelCit = [[CountryModel alloc]initWithDic:dic];
            [self.cityArr addObject:modelCit];
        }

        if (self.cityArr.count >= 4) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];
            NSURL *trafficUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[1]).appview_url];
            NSURLRequest *trafficRequest = [NSURLRequest requestWithURL:trafficUrl];
            [self.trafficWebView loadRequest:trafficRequest];
            NSURL *costUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[2]).appview_url];
            NSURLRequest *costRequest = [NSURLRequest requestWithURL:costUrl];
            [self.costWebView loadRequest:costRequest];
            NSLog(@"%@",costRequest);
            NSURL *PracticalUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[3]).appview_url];
            NSURLRequest *PracticalRequest = [NSURLRequest requestWithURL:PracticalUrl];
            [self.PracticalWebView loadRequest:PracticalRequest];
            self.scrollView.contentSize = CGSizeMake(WIDTH * 1500, 0);
            
        }else if (self.cityArr.count == 3) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];
            NSURL *trafficUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[1]).appview_url];
            NSURLRequest *trafficRequest = [NSURLRequest requestWithURL:trafficUrl];
            [self.trafficWebView loadRequest:trafficRequest];
            NSURL *costUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[2]).appview_url];
            NSURLRequest *costRequest = [NSURLRequest requestWithURL:costUrl];
            [self.costWebView loadRequest:costRequest];

            self.scrollView.contentSize = CGSizeMake(WIDTH * 1125, 0);
        }else if (self.cityArr.count == 2) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];
            NSURL *trafficUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[1]).appview_url];
            NSURLRequest *trafficRequest = [NSURLRequest requestWithURL:trafficUrl];
            [self.trafficWebView loadRequest:trafficRequest];
            self.scrollView.contentSize = CGSizeMake(WIDTH * 750, 0);
        }else if (self.cityArr.count == 1) {
            NSURL *destinationUrl = [NSURL URLWithString:((CountryModel *)self.cityArr[0]).appview_url];
            NSURLRequest *destinationRequest = [NSURLRequest requestWithURL:destinationUrl];
            [self.destinationWebView loadRequest:destinationRequest];
               self.scrollView.contentSize = CGSizeMake(WIDTH * 375, 0);
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100 * WIDTH, 30 * HEIGHT)];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.text = @"去哪旅行";
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = self.titleLabel;
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 375, HEIGHT * 667)];
    [self.view addSubview:self.scrollView];
   
    self.scrollView.contentOffset = CGPointMake(0, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.destinationWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 375, HEIGHT * 667)];
    self.destinationWebView.delegate = self;

    [self.scrollView addSubview:self.destinationWebView];
    self.trafficWebView = [[UIWebView alloc]initWithFrame:CGRectMake(WIDTH * 375, 0, WIDTH * 375, HEIGHT * 667)];
    self.trafficWebView.delegate = self;
    self.trafficWebView.clipsToBounds = NO;
    [self.scrollView addSubview:self.trafficWebView];
    self.costWebView = [[UIWebView alloc]initWithFrame:CGRectMake(WIDTH* 750, 0, WIDTH * 375, HEIGHT * 667)];
    self.costWebView.delegate = self;
    [self.scrollView addSubview:self.costWebView];
    self.PracticalWebView = [[UIWebView alloc]initWithFrame:CGRectMake(WIDTH * 1125, 0, WIDTH * 375, HEIGHT * 667)];
    self.PracticalWebView.delegate = self;
    [self.scrollView addSubview:self.PracticalWebView];
     [self creatData];
    // 左上角返回图标
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:(UIBarButtonItemStylePlain) target:self action:@selector(leftAction:)];
}

// 返回
- (void)leftAction:(UIBarButtonItem *)barButton {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [MBProgressHUD showHUDAddedTo:webView animated:YES];
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUDForView:webView animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
